package com.example.springbootdemo.mapper;

import com.example.springbootdemo.bean.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper {
    @Select("<script>select * from goods where 1=1 <if test='goods.id!=null'>and id=#{goods.id} </if><if test='goods.name!=\"\"'>and name like concat('%', #{goods.name}, '%') </if><if test='maxPrice!=null'>and price &lt;= #{maxPrice} </if><if test='minPrice!=null'>and price &gt;= #{minPrice} </if><if test='order==\"asc\"'>order by price asc </if><if test='order==\"desc\"'>order by price desc </if></script>")
    public List<Goods> SelectGoods(@Param("goods") Goods goods,@Param("minPrice") Integer minPrice,@Param("maxPrice") Integer maxPrice, @Param("order") String order);
    @Select("select * from goods")//1.本功能的sql语句
    List<Goods> selectAll();//2.定义这个方法，方便调用
    @Update("update goods set is_deleted = 1 where id = #{id}")
    int DeleteGoods(@Param("id") int id);
    @Insert("INSERT INTO goods VALUES (null, #{name}, #{info}, #{price}, #{imgsrc}, #{typeId}, #{num}, #{is_deleted})")
    int insertGoods(Goods goods);
}